package com.ikas.ai.utils;

import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HXH
 * @date 2018/7/31
 */
public class CollectionUtil extends CollectionUtils {
    /**
     * 把数据库查出来字典表，list格式的转成map,id列为key,name列为value,id是数字
     *
     * @param list
     * @return
     */
    public static Map<Integer, String> dictList2map(List<Map<String, Object>> list) {
        Map<Integer, String> resultMap = new HashMap<Integer, String>();
        for (Map<String, Object> tmp : list) {
            if (null == tmp.get("id")) {
                resultMap.put(Integer.parseInt(tmp.get("ID").toString()), (String) tmp.get("NAME"));
            } else {
                resultMap.put(Integer.parseInt(tmp.get("id").toString()), tmp.get("name") + "");
            }

        }
        return resultMap;
    }

    public static Map<Integer, String> dictList2maps(List<Map<String, Object>> list) {
        Map<Integer, String> resultMap = new HashMap<Integer, String>();
        for (Map<String, Object> tmp : list) {
            if (null == tmp.get("name")) {
                resultMap.put(Integer.parseInt(tmp.get("EVENTTYPE").toString()), (String) tmp.get("NAME"));
            } else {
                resultMap.put(Integer.parseInt(tmp.get("eventType").toString()), tmp.get("name") + "");
            }

        }
        return resultMap;
    }


    public static Map<String, String> alarmList2maps(List<Map<String, Object>> list) {
        Map<String, String> resultMap = new HashMap<>();
        for (Map<String, Object> tmp : list) {
            if (null == tmp.get("name")) {
                resultMap.put((String) tmp.get("NAME"), tmp.get("EVENTTYPE").toString());
            } else {
                resultMap.put(tmp.get("name") + "", tmp.get("eventType").toString());
            }

        }
        return resultMap;
    }

    /**
     * 把数据库查出来字典表，list格式的转成map,id列为key,name列为value,id是string
     *
     * @param list
     * @return
     */
    public static Map<String, String> dictList2mapString(List<Map<String, Object>> list) {
        Map<String, String> resultMap = new HashMap<String, String>();
        for (Map<String, Object> tmp : list) {
            if (null == tmp.get("id")) {
                resultMap.put((String) tmp.get("ID"), (String) tmp.get("NAME"));
            } else {
                resultMap.put((String) tmp.get("id"), (String) tmp.get("name"));
            }
        }
        return resultMap;
    }

    public static Map<String, Long> cameraLoationTypeList2mapString(List<Map<String, String>> list) {
        Map<String, Long> resultMap = new HashMap<>();
        for (Map<String, String> tmp : list) {
            String a = String.valueOf( tmp.get("cameraLocationType"));
            Long b =  Long.valueOf(String.valueOf(tmp.get("num")));
            resultMap.put(String.valueOf( tmp.get("cameraLocationType")) ,  Long.valueOf(String.valueOf(tmp.get("num"))));
        }
        return resultMap;
    }
}
